import { translate } from './i18n';

world.onPlayerJoin(async ({ entity }) => {
    entity.k1 = false
    entity.k2 = false
    entity.k3 = false
    entity.key = 0
    entity.indoor = true
})

const weapon = world.querySelector('#武器钥匙')
if (weapon) {
    weapon.enableInteract = true
    weapon.interactRadius = 1
    weapon.interactHint = `拾取（武器钥匙）`
    weapon.onInteract(async ({ entity }) => {
        entity.onHand = `武器钥匙`
        entity.player.directMessage(translate('你获得了武器钥匙，{onHand}放回原位', entity?.language || 'zh', { onHand: entity.onHand }))
    })
}

const mw = world.querySelector('#木屋钥匙')
if (mw) {
    mw.enableInteract = true
    mw.interactRadius = 3
    mw.interactHint = `拾取（木屋钥匙）`
    mw.onInteract(async ({ entity }) => {
        entity.player.directMessage(translate('你获得了木屋钥匙，现在开始，你可以进入木屋了', entity?.language || 'zh'))
        entity.bq.push('进入木屋')
        entity.addTag('木屋')
    })
}

const key_safe = world.querySelector('#安全钥匙')
if (key_safe) {
    key_safe.enableInteract = true
    key_safe.interactRadius = 3
    key_safe.interactHint = `拾起（安全钥匙）`
    key_safe.onInteract(async ({ entity }) => {
        entity.addTag('安全钥匙')
        entity.bq.push('安全钥匙')
        entity.player.directMessage(translate('成功拾起安全钥匙', entity?.language || 'zh'))
    })
}

const key_1 = world.querySelector('#金钥匙-1')
if (key_1) {
    key_1.enableInteract = true
    key_1.interactRadius = 3
    key_1.interactHint = `拾起`
    key_1.onInteract(async ({ entity }) => {
        if (entity.key < 3) {
            if (entity.k1 == false) {
                entity.key += 1
                entity.k1 = true
                entity.player.directMessage(translate('成功拾起钥匙，目前手持钥匙{key}/3把', entity?.language || 'zh', { key: entity.key }))
            }
        }
    })
}

const key_2 = world.querySelector('#金钥匙-2')
if (key_2) {
    key_2.enableInteract = true
    key_2.interactRadius = 3
    key_2.interactHint = `拾起`
    key_2.onInteract(async ({ entity }) => {
        if (entity.key < 3) {
            if (entity.k2 == false) {
                entity.key += 1
                entity.k2 = true
                entity.player.directMessage(translate('成功拾起钥匙，目前手持钥匙{key}/3把', entity?.language || 'zh', { key: entity.key }))
            }
        }
    })
}

const key_3 = world.querySelector('#金钥匙-3')
if (key_3) {
    key_3.enableInteract = true
    key_3.interactRadius = 3
    key_3.interactHint = `拾起`
    key_3.onInteract(async ({ entity }) => {
        if (entity.key < 3) {
            if (entity.k3 == false) {
                entity.key += 1
                entity.k3 = true
                entity.player.directMessage(translate('成功拾起钥匙，目前手持钥匙{key}/3把', entity?.language || 'zh', { key: entity.key }))
            }
        }
    })
}

// const mw = world.querySelector('#木屋钥匙')
// mw.enableInteract = true
// mw.interactRadius = 3
// mw.interactHint = `拾取（木屋钥匙）`
// mw.onInteract(async({entity}) => {
//     entity.player.directMessage(`你获得了木屋钥匙，现在开始，你可以进入木屋了`)
//     entity.addTag('木屋')
// })


const qc = world.querySelector('#跑车钥匙-1')
if (qc) {
    qc.enableInteract = true
    qc.interactRadius = 3
    qc.interactHint = `拾取（汽车钥匙）`
    qc.onInteract(async ({ entity }) => {
        entity.addTag('汽车')
        entity.bq.push('开启汽车后备箱')
        entity.player.directMessage(translate('你获得了汽车钥匙', entity?.language || 'zh'))
    })
}